(in-package :cl-daisyui)

(defmacro button (class label &rest attributes)
  `(spinneret:with-html
     (:button :class ,class ,@attributes ,label)))

(defmacro summary (label class &rest attributes)
  `(spinneret:with-html
     (:summary :class ,class ,@attributes ,label)))

(defmacro dropdown/details (class summary-node &body body)
  "Dropdown implements using details and summary tags. Stays open until gets clicked again. Or you can close it using JS by removing the `open` attribute.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details"
  `(spinneret:with-html
     (:details :class ,class
               ,summary-node
               ,@body)))

(defmacro tabindex (label &optional (class "btn") (index "0") (role "button"))
  ;; (tabindex "Click" "btn m-1" "0" "button")
  `(spinneret:with-html
     (:div :tabindex ,index :role ,role :class ,class ,label)))

(defmacro dropdown/css-focus (class tabindex-node &body body)
  "Dropdown implements using CSS focus.
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex"
  `(spinneret:with-html
     (:div :class ,class
           ,tabindex-node
           ,@body)))

(defmacro modal/dialog (class element-id docker-node &body body)
  "Modal implements with dialog.
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex"
  `(spinneret:with-html
     ,docker-node
     (:dialog :id ,element-id :class ,class
              ,@body)))

(defmacro swap (class &optional (on "ON") (off "OFF"))
  ;; (swap "swap")
  `(spinneret:with-html
     (:label :class ,class
             (:input :type "checkbox")
             (if (stringp ,on)
                 (:div :class "swap-on" ,on)
                 ,on)
             (if (stringp ,off)
                 (:div :class "swap-off" ,off)
                 ,off))))
